package com.pt25.base.dep.nacos.rpc;

import com.pt25.base.dep.nacos.rpc.ddo.RpcData;
import com.pt25.base.util.TokenUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Calendar;

@Component
public class RpcService {

    @Resource
    private RpcProperties rpcProperties;

    public String getToken() {
        RpcData rpcData = RpcData.builder()
                .secretKey(rpcProperties.getSecretKey())
                .reqTimes(System.currentTimeMillis())
                .build();
        //设置rpc token的过期时间为10s
        return TokenUtil.encryptToken(rpcData, rpcProperties.getSecretKey(), Calendar.SECOND, 10);
    }
}
